<div id="buttonContainer" class="content">
<div id="buttonScrollBox" class="scrollBox">
<?php
	$_GET['prefix'] = 'btn';
	if(isset($active_ctg_id)) {
		if (!isset($_GET['ctg_id'])) {
			$_GET['ctg_id'] = $active_ctg_id;
		}
	}
	if(isset($active_prj_id)) {
		if (!isset($_GET['prj_id'])) {
			$_GET['prj_id'] = $active_prj_id;
		}
	}
	include 'lib/php/load.php';
	ob_end_clean();
	$buttons = $items;
	$btn_coords = array();
	$i = 0;
	foreach ($buttons as $id => $item) {
		if(isset($_GET['btn_id'])) {
			if($id == $_GET['btn_id']) {
				displayBtn($id, $item, true);
			} else {
				displayBtn($id, $item, false);
			}
		} else {
			displayBtn($id, $item, false);
		}
		array_push($btn_coords, "$item[x]$item[y]");
		$i++;
	}
	echo '<div id="dummies">';
	for($x=0; $x < 6; $x++) {
		for($y=0; $y < 5; $y++) {
			if(!in_array("$x$y", $btn_coords)) {
				echo "	<div id='dummy_$x$y' class=\"dummy item\" style=\"left: ".(80*$x)."px; top: ".(80*$y)."px; z-index: 0;\"></div>\n";
			}
		}
	}
	echo '</div>';
?>
</div>
</div>

<?php 
function displayBtn($id, $item, $active) {
	$interactive = $item[interactive];
	$active = $interactive == true ? $active : true;
	$prefix = $item[prefix];
	$div_id = $prefix."_".$id;
	$alias = $item[alias];
	$label = $item[label];
	$thumb = $item[thumb];
	$thumb_enable = $item[thumb_enable];
	$link = $item[link];
	$link_enable = $item[link_enable];
	$text = $item[text];
	$text_enable = $item[text_enable];
	$img = $item[img];
	$img_preview = substr_replace($img, '_preview', strrpos($img, '.'), 0);
	$img_title = $item[img_title];
	$img_enable = $item[img_enable];
	$lightbox_enable = $item[lightbox_enable];
	$img_rel = $lightbox_enable ? "shadowbox[$prefix]" : "";
	$ctg = $item[category_id];
	$prj = $item[project_id];
	$site_link = $active == false ? "index.php?prefix=$item[prefix]&amp;ctg_id=$ctg&amp;prj_id=$prj&amp;btn_id=$id" : "index.php?prefix=$item[prefix]&amp;ctg_id=$ctg&amp;prj_id=$prj";
	$x = $active == false ? 80*$item[x] : 80*$item[content_x];
	$y = $active == false ? 80*$item[y] : 80*$item[content_y];
	$width = $active == false ? 73 : 80*$item[content_width]-7;
	$height = $active == false ? 73 : 80*$item[content_height]-7;
	$z = $active == true ? 99 : 0;
	$cursor = $interactive == true ? 'cursor: pointer;' : '';
	if(!empty($label) || !empty($thumb)) $bg = "background: #232323;";
	else $bg = "";
	$class_active = $active == true ? 'active' : '';
	$class = 'item btn'.' '.$item[item_class].' '.$class_active;
	
	//Navigations Link nur erstellen wenn keine Lightbox aktiviert ist, 
	//oder falls lightbox aktiv ist, dann nur wenn dieser button nicht der aktive button ist
	if ($nav_link = $interactive) {
		if ($lightbox_enable) {
			if ($active) {
				$nav_link = false;
			}
		}
	}
	//Externer Link nur erstellen wenn keine Lightbox aktiviert ist, 
	//oder falls lightbox aktiv ist, dann nur wenn dieser button nicht der aktive button ist
	if (!empty($link)) {
		if ($external_link = $link_enable) {
			if ($lightbox_enable) {
				if ($active) {
					$external_link = false;
				}
			}
		}
	} else {
		$external_link = false;
	}
	
	$html = array("<div id='btn_$id' class='$class' style='left:".$x."px; top:".$y."px; width: ".$width."px; height: ".$height."px; z-index: $z; $bg $cursor'>\n");
	if(!empty($thumb) && $thumb_enable && !$active) 						array_push($html, "	<img id='thumb_$div_id' class='thumb' src='$thumb' alt='$alias' width='73' height='73' />\n");
	if(!empty($label) && !$active) 											array_push($html, "	<div id='label_$div_id' class='label'>$label</div>\n");
	if(!empty($img) && $img_enable && $active && !$lightbox_enable) 		array_push($html, "	<img id='img_$div_id' class='img' src='$img_preview' alt='$img_title' title='$img_title' width='".(80*$item[content_width]-7)."' height='".(80*$item[content_height]-7)."' />\n");
	else if (!empty($img) && $img_enable && $active && $lightbox_enable) 	array_push($html, "<a href='$img' rel='$img_rel' class='lightbox' target='blank'> <img id='img_$div_id' class='img' src='$img_preview' alt='$alias' title='$img_title' width='".(80*$item[content_width]-7)."' height='".(80*$item[content_height]-7)."' /></a>\n");
	if(!empty($text) && $text_enable && $active && empty($img)) 			array_push($html, "	<div id='text_$div_id' class='text' >$text</div>\n");
	if(!empty($text) && $text_enable && $active && !empty($img))			array_push($html, "	<div id='text_$div_id' class='caption' >$text</div>\n");
	if($nav_link) 															array_push($html, "	<a id='innerlink_$div_id' class='link nav inner' href='$site_link'></a>\n");
	else if($external_link)													array_push($html, "	<a id='outerlink_$div_id' class='link nav outer' href='$link' target='_blank'></a>\n");
	array_push($html, "</div>\n");
	echo join('', $html);
}
?>